/*
 * Author: 李波(Edwin Lee)
 * Date: 2024-08-10 11:44:57
 * FilePath: /mprpc/src/mprpcconfig.cc
 * LastEditTime: 2024-08-11 08:52:18
 * version: 1.0
 * Description: 
 */
#include "public.h"
#include "mprpcconfig.h"
#include <fstream>
#include <sstream>
#include <cstdio>
#include <iostream>


void MprpcConfig::loadConfigFile(const char* configFile)
{
	std::ifstream file(configFile);
	std::string line;
	std::string key;
	std::string value;
	if (!file.is_open())
	{
        std::cout << configFile << "is not exist" << std::endl;
        exit(EXIT_FAILURE);
    }

	while (getline(file, line))
	{
		strTrim(line);
		if ('#' == line[0])                         //第一个字符为#此行为注释
			continue;
		std::istringstream istr(line);           //需要头文件<sstream>
		if (getline(istr, key, '='))
		{
			if (getline(istr, value))
				configMap_[key] = value;
		}
	}
	file.close();
}

// 查询配置项信息
std::string MprpcConfig::load(const std::string& key)
{
	auto it = configMap_.find(key);
	if(configMap_.end() == it)
	{
		return "";
	}
	return it->second;
}